package org.yjc.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.yjc.entity.Course;
import org.yjc.repository.CourseRepository;

@Service
public class CourseService {
	@Autowired
	private CourseRepository courseDAO;

	public Page<Course> findAll(Pageable pageable) {	
		return courseDAO.findAll(pageable);
	}

	public void deleteById(Integer id) {
		courseDAO.deleteById(id);
	}

	public void save(Course course) {
		courseDAO.save(course);
	}

	public Page<Course> findAll(Specification spec, Pageable pageable) {
		return courseDAO.findAll(spec, pageable);
	}

	public List<Course> findAll() {
		return courseDAO.findAll();
	}

	public Course findById(Integer kcid) {
		Optional<Course> optional = courseDAO.findById(kcid);
		if(optional.isPresent()) {
			return optional.get();
		}
		return null;
	}

}
